
// 获取浏览器宽度
export const getWidth= () => {
  const w = document.documentElement.clientWidth;
  return w
}

// 防抖函数
export const debounce = (fn, wait) => {
  let timeout;
  const later = () => setTimeout( () => {
   timeout = null;
   fn() 
  }, wait);
  let debounced = function() {
    if(!timeout) {
      timeout = later();
    } else {
      clearTimeout(timeout);
      timeout = later();
    }
  }
  debounced.cancel = function() {
    clearTimeout(timeout);
    timeout = null;
  }
  return debounced;
}